<?
include("../lib/config.php");
$nik 	= $HTTP_GET_VARS['nik'];
$op		= $HTTP_GET_VARS['op'];
$no		= $HTTP_GET_VARS['no'];

if($op == "edit"){
	$Faction = "../lib/update.php";
	$Vbutton = "Update";
	$query	= mssql_query("WITH limit as (SELECT ROW_NUMBER() OVER (ORDER BY NIK) as No, kode, nama FROM Bahasa A, VBahasa B WHERE nik='$nik' and A.Bahasa=B.kode) Select * from limit where No='$no'",$conn);
	$row	= mssql_fetch_array($query);
}
else{
	$Faction = "../lib/save.php";
	$Vbutton = "Simpan";
}

include("../header.php");
	// khusus untuk administrasi user
	$sads = mssql_query("SELECT * FROM VPrivUser WHERE username='".$_SESSION['user_login']."' AND nama_menu='administrasi_user'",$conn);
	$rads = mssql_fetch_array($sads);
?>
<script type="text/javascript">
	function Validate(){
		if(document.F.group_code.value == "")
		{
			alert("Field : Kode Group tidak boleh kosong dan bernilai unik ...");
			document.F.group_code.focus();
			return false;
		}
		
		if(document.F.group_name.value == "")
		{
			alert("Field : Nama Group tidak boleh kosong dan bernilai unik ...");
			document.F.group_name.focus();
			return false;
		}
		
	}
</script>

<script type="text/javascript">
	function hapus(USR)
	{
		var ok = confirm("Apakah Anda yakin menghapus group user: "+ USR +"  ?");
		if(ok == true)
		{
			window.location.href="../lib/delete.php?cat=add_group&usr="+USR+"";
		}
		else
		{
		}
	}
</script>

</head>
<table width="93%" class="table_indent2" class="no_border">
 <tr>
  <td colspan="2">
	<table width="100%" style="border:none;">
	<tr>
	 <td colspan="2" class="line_bottom">&nbsp;&nbsp;<b>GROUP USER</b></td>
	</tr>
	</table>
  </td>
 </tr>
 <tR>
  <td align="right">
	  <?
        if($rads[tambah] == 1){
      ?>
  <input type="button" class="button" value="Tambah Group USer" onclick="Javascript:location.href='frm_adm_add_group.php'" />
  <input type="button" class="button" value="Tambah User" onclick="Javascript:location.href='frm_adm_add_user.php'" />
		<?
        }
        ?>  
  </td>
 </tR>
 <tr>
  <td>
  <fieldset><legend>Daftar Group User</legend>
   <table width="100%">
    <tr class="headlist">
     <td>Kode Group</td>
     <td>Nama Group</td>
     <td>Keterangan</td>
     <td>Hak Akses</td>
     <td colspan="2">&nbsp;</td>
    </tr>
    <?
    include("../lib/config.php");
	$sql = mssql_query("SELECT * FROM S_User_Group ORDER BY group_name ASC",$conn);
	while($row = mssql_fetch_array($sql)){
		echo"
		 <tr class=contentlist>
		  <td>$row[group_id]</td>
		  <td>$row[group_name]</td>
		  <td>$row[note]</td>
		  <td>";
		  $sq = mssql_query("SELECT * FROM S_Priv_User WHERE group_id='$row[group_id]'",$conn);
		  echo"
		  <table align=center width=100% cellspacing=1 cellpadding=0 bgcolor='#FFFFFF' >
		  <tr class=headlist>
		   <td>Nama Menu</td>
		   <td>View</td>
		   <td>Tambah</td>
		   <td>Edit</td>
		   <td>Hapus</td>
		   <td>Approval</td>
		  </tr>
		  ";
		  while($ro = mssql_fetch_array($sq)){
		   	echo"<tr bgcolor='#EFEFEF'>
				<td>".strtoupper($ro[nama_menu])."";
			// get keterangan cabang
			$sad = mssql_query("select * from vcabang where Kode_Cabang='".$ro[nama_menu]."'",$conn);
			if(mssql_num_rows($sad) > 0){
				$rad = mssql_fetch_array($sad);
				echo " - ".strtoupper($rad[1])."";
			}
			echo"</td>
				<td>";
				if($ro[baca] == 1){
					echo"<center><img src='../images/apply.png'></center>";
				}
			echo"</td><td>";
				if($ro[tambah] == 1){
					echo"<center><img src='../images/apply.png'></center>";
				}			
			echo"</td><td>";
				if($ro[edit] == 1){
					echo"<center><img src='../images/apply.png'></center>";
				}
			echo"</td><td>";
				if($ro[hapus] == 1){
					echo"<center><img src='../images/apply.png'></center>";
				}			
			echo"</td><td>";
				if($ro[approval] == 1){
					echo"<center><img src='../images/apply.png'></center>";
				}			
			echo"</td><td>";
		   	echo"</tr>";
		   }
		  echo"</table>
		  ";
		echo"</td>
		<td width=1%>";
		// edit
		if($rads[edit] == 1){
		echo"<a href='frm_adm_add_group.php?op=edit&amp;g=$row[group_id]'><img src='../images/b_edit.png' border='0'></a>";
		}
		
		echo"</td>";
		// delete
		if($rads[hapus] == 1){
			$su = mssql_query("select groupid from s_user where groupid='$row[group_id]'");
			if(mssql_num_rows($su) > 0){
			echo"<td width=1%><img src='../images/b_delete.png' border='0'></td>";
			}
			else{
			echo"<td width=1%><a href='#' onclick=\"hapus('$row[group_id]');\"><img src='../images/b_delete.png' border='0'></a></td>		";
			}
		}
		echo"
		</tr>
		";
	}
	?>
   </table>
   </fieldset>
  </td>
 </tr>
</table>
<?
echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>